<template>
  <a-modal v-model:visible="visible" title="医师资格证" :footer="null">
    <div class="card details">
      <span class="icon-box"></span>
      <div class="content">
        <div>
          <a-tooltip>
            <template #title>{{ data?.identityName || '' }}</template>
            {{ data?.identityName || '' }}
          </a-tooltip>
        </div>
        <div>
          <span>发行机构：</span>
          <a-tooltip>
            <template #title>{{ data.companyName }}</template>
            {{ data.companyName }}
          </a-tooltip>
        </div>
      </div>
    </div>
    <div class="identity-details">
      <div class="item-title">身份介绍</div>
      <p>{{ data?.identityDescription || '' }}</p>
      <div class="item-title">身份信息</div>
      <a-row class="row-info" v-for="item in identityTemplate" :key="item.questionId">
        <a-col :span="12">{{ item.name }}</a-col>
        <a-col :span="12">{{ item.value }}</a-col>
      </a-row>
    </div>
  </a-modal>
</template>

<script lang="ts" setup>
  import { computed, onUpdated, ref } from 'vue'

  import { requestGetIdentityInfoById } from '/@/api/business/identity'
  import { HttpCodeEnum } from '/@/enums/httpEnum'
  const props = defineProps({
    visible: { type: Boolean, default: false },
    id: { type: String, default: '' },
  })
  const data: any = ref({})
  const identityTemplate: any = ref([])
  const getIdentityInfoById = async () => {
    const { responseCode, responseData } = await requestGetIdentityInfoById({
      id: props.id,
    })
    if (responseCode === HttpCodeEnum.SUCCESS) {
      data.value = responseData
      identityTemplate.value = JSON.parse(data.value.identityTemplateExample)
      console.log(identityTemplate.value)
    }
  }

  onUpdated(() => {
    data.value = []
    identityTemplate.value = []
    props.id && getIdentityInfoById()
  })
  const emits = defineEmits(['update:visible'])

  const visible = computed({
    get: () => props.visible,
    set: (val) => emits('update:visible', val),
  })
</script>

<style lang="less">
  .card {
    float: left;
    width: 320px;
    height: 80px;
    color: rgb(255 255 255 / 86%);
    font-size: 16px;
    font-weight: 600;
    border-radius: 16px;
    margin: 0 12px 12px 0;
    padding: 16px;
    box-sizing: border-box;
    display: flex;

    &:nth-child(1n + 0) {
      background: linear-gradient(90deg, #cf1322 0%, #ff4d4f 100%);

      .icon-box {
        background-image: url('/@/assets/images/views/org/icon-1.png');
      }
    }

    &:nth-child(2n + 0),
    &.details {
      background: linear-gradient(90deg, #08979c 0%, #13c2c2 100%);

      .icon-box {
        background-image: url('/@/assets/images/views/org/icon-2.png');
      }

      &.details {
        width: 470px;
      }
    }

    &:nth-child(3n + 0) {
      background: linear-gradient(90deg, #ab8200 0%, #d4ab29 100%);

      .icon-box {
        background-image: url('/@/assets/images/views/org/icon-3.png');
      }
    }

    .icon-box {
      display: inline-block;
      width: 48px;
      height: 48px;
      background: #fff;
      border-radius: 50%;
      background-size: 48px 48px;
    }

    .content {
      margin-left: 12px;
      display: flex;
      flex-direction: column;
      width: 230px;

      > div:nth-child(2) {
        font-size: 14px;
        color: rgb(255 255 255 / 60%);
      }

      div {
        overflow: hidden;
        white-space: normal;
        text-overflow: ellipsis;
        height: 30px;
        width: 100%;
      }
    }
  }

  .identity-details {
    clear: both;
    background: #f2f3f5;
    border-radius: 16px;
    padding: 22px 24px;
    font-size: 14px;
    color: rgb(0 0 0 / 65%);

    .item-title {
      font-weight: 500;
      color: #000;
      margin-bottom: 8px;

      &:nth-of-type(2) {
        margin-top: 24px;
      }
    }

    .row-info {
      padding: 12px 0;

      &:not(:nth-last-of-type(1)) {
        border-bottom: 1px solid rgb(0 0 0 / 8%);
      }

      div:nth-child(1) {
        font-weight: 400;
        color: #000;
      }

      div:nth-child(2) {
        text-align: right;
      }
    }
  }
</style>
